<?php
namespace tools;
use PDO;
use Exception;
class Model{
    private static $pdo=null;
    public function __construct()
    {
        if(is_null(self::$pdo)){
            try{
                $dsn='mysql:host=localhost;dbname=student';
                self::$pdo=new PDO($dsn,'homestead','secret');
                self::$pdo->query('set names utf8');
                self::$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);


            }catch (Exception $exception){
                die($exception->getMessage());
            }
        }
    }
    public function query($sql){
        try{
            return self::$pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
        }catch(Exception $exception){
            die($exception->getMessage());
        }
    }
    public function query_edit($sql){
        try{
            return self::$pdo->query($sql)->fetch(PDO::FETCH_ASSOC);
        }catch(Exception $exception){
            die($exception->getMessage());
        }
    }

    public function exec($sql){
        try{
            return self::$pdo->exec($sql);
        }catch(Exception $exception){
            die($exception->getMessage());
        }
    }


}